package com.fifth.order.controller;

import com.fifth.common.pojo.dto.CommonResult;
import com.fifth.common.pojo.entity.Cart;
import com.fifth.order.service.CartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @作者：刘壬杉
 * @创建时间 2022/9/1 14:17
 **/
@RestController
@RequestMapping("order/cart")
@Api(tags = "购物车相关接口")
public class CartController {
    @Autowired
    private CartService cartService;

    /**
     * 点击添加购物车按钮添加商品到购物车
     * @param cart
     * @return 2000成功 4000登录失效 5000添加失败 6000已存在该商品
     */
    @ApiOperation(value = "点击购物车添加商品")
    @PostMapping("addCart")
    public CommonResult addCart(@RequestBody Cart cart){
        return cartService.addCart(cart);
    }

    /**
     * 点击我的购物车查询所有购物车信息
     * @return List<Cart>
     */
    @ApiOperation(value = "查询购物车信息")
    @GetMapping("findCart/{currentPage}/{pageSize}")
    public CommonResult findCart(@PathVariable Integer currentPage,@PathVariable Integer pageSize){
        return cartService.findCart(currentPage,pageSize);
    }

    /**
     * 根据购物车id删除购物车
     * @param id
     * @return
     */
    @ApiOperation("删除购物车")
    @GetMapping("deleteCart/{id}")
    public CommonResult deleteCart(@PathVariable String id){
        return cartService.deleteCart(id);
    }

    /**
     * 根据ids批量删除
     * @param ids
     * @return
     */
    @ApiOperation("根据ids批量删除")
    @PostMapping("deleteByIds")
    public CommonResult deleteByIds(@RequestBody String[] ids){
        return cartService.deleteByIds(ids);
    }
}
